package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.goods.Spu;
import com.qingcheng.service.AddAndDeleteEsService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.UnsupportedEncodingException;


public class AddEsSpuMessageConsumer implements MessageListener {



    @Autowired
    private AddAndDeleteEsService addAndDeleteEsService;

    public void onMessage(Message message) {

        String jsonStr = null;
        try {
            //设置字符集 防止出现乱码
            jsonStr = new String(message.getBody(),"utf-8");
            Spu spu = JSON.parseObject(jsonStr, Spu.class);

            addAndDeleteEsService.addEs(spu);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
}
